/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.utl.ist.isr.livetrack.server;

import gnu.cajo.utils.extra.TransparentItemProxy;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;

/**
 *
 * @author David Miguel Antunes <davidmiguel [ at ] antunes.net>
 */
public class DistributionUtils {

    private static final Logger logger = Logger.getLogger(DistributionUtils.class);

    private DistributionUtils() {
    }

    public static <T> Set<T> proxySet(Set<T> set) {
        Set<T> proxies = new HashSet<T>();
        for (T elem : set) {
            proxies.add((T) TransparentItemProxy.getItem(elem, elem.getClass().getInterfaces()));
        }
        return (Set<T>) TransparentItemProxy.getItem(proxies, proxies.getClass().getInterfaces());
    }

    public static <K, V> Map<K, V> proxyMap(Map<K, V> map) {
        Map<K, V> proxies = new HashMap<K, V>();
        for (Map.Entry<K, V> entry : map.entrySet()) {
            proxies.put(entry.getKey(),
                    (V) TransparentItemProxy.getItem(entry.getValue(), entry.getValue().getClass().getInterfaces()));
        }
        return (Map<K, V>) TransparentItemProxy.getItem(proxies, proxies.getClass().getInterfaces());
    }

    public static <T> T proxyObj(T obj) {
        return (T) TransparentItemProxy.getItem(obj, obj.getClass().getInterfaces());
    }
}
